package ij.umasuo.AOTFController;

import ij.IJ;
import ij.ImagePlus;

import java.awt.Image;

import javax.swing.SwingUtilities;

/**
 * live model controller
 * @author liuquan
 * @date 2013-08-22
 * @version 1.0
 *
 */
public class LiveCtr implements CtrInterface{

//	private LiveViewer liveViewer = null;
	private static boolean isLivingOn = false;
	private static LiveCtr instance = null;
	private static ImagePlus imp = null;
	
	private LiveCtr(){}
	
	@Override
	public ImagePlus getNextImage() {
		return null;
	}

	@Override
	public ImagePlus getNextImage(int channel) {
		return null;
	}

	@Override
	public int getNextChannel() {
		return 0;
	}

	@Override
	public int getTotalImageCount() {
		return 0;
	}
	
	@Override
	public String getNextImagePath() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getNextImagePath(int channel) {
		// TODO Auto-generated method stub
		return null;
	}

	public static LiveCtr getInstance(){
		if(instance == null){
			instance = new LiveCtr();
		}
		return instance;
	}
	
	public boolean isLivingON(){
		return isLivingOn;
	}
	
	/**
	 * 
	 */
	public void startLiveModel(){
		isLivingOn = true;
		Thread thread = new Thread(new Runnable(){//start a new thread to invoke the plugin
			@Override
			public void run() {
				IJ.runPlugIn("CameraPlugin", "live:0");//this is a block method
			}
		});
		thread.start();
	}
	
	public void stopLiveModel(){
		isLivingOn = false;
	}
	
	/**
	 * add a new image to the list
	 * @param imp
	 */
	public void setImage(ImagePlus imp){
		LiveCtr.imp = imp;
	}
	
	public Image getImage(){
		if(imp == null){
			return null;
		}
		return imp.getImage();
	}

	@Override
	public int getNextFrame() {
		// TODO Auto-generated method stub
		return 0;
	}

}
